 <?php




include_once "callback/WXBizMsgCrypt.php";

// 假设企业号在公众平台上设置的参数如下

$encodingAesKey = "S6CB9goX7KGrrIK6fVe3cBrpX5rVkQEUssFTDBriQK5";
$token = "RCcTvDPohI1aP6Z2e8yxdytD9n051XjV";
$corpId = "wxa75fd57348cec1d7";
//设置utf-8应该是最最最关键的一步
header("Content-Type:text/html; charset=utf-8");
$sVerifyMsgSig = $_GET['msg_signature'];
$sVerifyTimeStamp = $_GET['timestamp'];
$sVerifyNonce = $_GET['nonce'];
$sVerifyEchoStr = $_GET['echostr'];
$EchoStr = '';
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);

if (isset($_GET['echostr'])) {
    if ($errCode == 0) {
        echo $sEchoStr;
    } else {
        print("ERR: " . $errCode . "\n\n");
    }exit;
}
responseMsg();

function responseMsg() {




    $encodingAesKey = "S6CB9goX7KGrrIK6fVe3cBrpX5rVkQEUssFTDBriQK5";
    $token = "RCcTvDPohI1aP6Z2e8yxdytD9n051XjV";
    $corpId = "wxa75fd57348cec1d7";

    $getD = $_GET;
    $testxml = file_get_contents("php://input");
    $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
    $wxcpt->DecryptMsg($getD['msg_signature'],$getD['timestamp'],$getD['nonce'],$testxml,$A);
    $jsonxml = json_encode(simplexml_load_string($A, 'SimpleXMLElement', LIBXML_NOCDATA));
    $jsonArr = json_decode($jsonxml,true);
    $ev = $jsonArr['Event'];
    $id = $jsonArr['FromUserName'];
//    $A1 = json_encode($jsonArr);
//    $connect = mysqli_connect('rm-uf66r00j217i4egckzo.mysql.rds.aliyuncs.com','root2','WWWlife8','salesman','3306');
//    $sal =     $sql = "INSERT INTO sh_crm_ceshi (var) VALUES ('$A1')";
//          mysqli_query($connect,'SET NAMES UTF8');
//
//           $result = mysqli_query($connect,$sal);

    if($ev=='subscribe'){//关注
        $url='http://xlt.shared123.cn/crm/sample/subscribe?staff_id='.$id;
        file_get_contents($url);
    }elseif ($ev=='unsubscribe'){
        $url='http://xlt.shared123.cn/crm/sample/Nosubscribe?staff_id='.$id;
        file_get_contents($url);
    }



}













